import { promiseRequest, getOpenId } from "../../../utils/index";
const app = getApp();
Page({
  data: {
    shopName: '',
    shopAddress: '',
    shopTypeCode: '',
    shopTypeText: '',
    tele: '',
    weixin:'',
    shopdesc:'',
    shoptypepicker:["微商","商户"]
  },
  onLoad(query) {
  },
  onShow() {
  },
  bindshopName(e) {
    this.setData({
      shopName: e.detail.value
    })
  },
  bindshopAddress(e) {
    this.setData({
      shopAddress: e.detail.value
    })
  },
shopTypeChange(e) {
  this.setData({
    shopTypeCode: e.detail.value,
    shopTypeText: this.data.shoptypepicker[e.detail.value]
  })
},
bindtele(e) {
    this.setData({
      tele: e.detail.value
    })
},
bindweixin(e) {
  this.setData({
    weixin: e.detail.value
  })
},
bindshopdesc(e) {
  this.setData({
    shopdesc: e.detail.value
  })
},
//保存商户信息
saveshopinfo() {
  let shopName = this.data.shopName;//商户名称
  let shopAddress = this.data.shopAddress;//商户地址
  let shopTypeCode = this.data.shopTypeCode;//商户类型
  let shopTypeText = this.data.shopTypeText;//商户类型名称
  let tele = this.data.tele;//商户手机
  let weixin = this.data.weixin;//商户微信
  let shopdesc = this.data.shopdesc;//商户简介

  if (shopName == '') {
    wx.showToast({
      title: '商户名称不能为空!',
      icon: 'none'
    });
    return;
  }
  if (shopAddress == '') {
    wx.showToast({
      title: '商户地址不能为空!',
      icon: 'none'
    });
    return;
  }
  if (shopTypeCode == '') {
    wx.showToast({
      title: '商户类型不能为空!',
      icon: 'none'
    });
    return;
  }
  //保存商家信息
  let openid = getOpenId();
  var thirdparty = { openid: openid, shopName: shopName, shopAddress: shopAddress, shopTypeCode: shopTypeCode, shopTypeText: shopTypeText, tele: tele, weixin: weixin, shopdesc: shopdesc};
  let requestObj = {
    url: '/wxa/actthirdparty/updateShopinfo',
    method: 'post',
    dataobj: thirdparty,
  };
  promiseRequest(requestObj).then((res) => {
    if(res.code == 200) {
      wx.showToast({
        title: '提交成功',
        icon: 'none'
      })
    }
  }).catch((errMsg) => {
  });
},
})